package com.fm.financemanage.controller;

import com.fm.financemanage.component.TokenComponent;
import com.fm.financemanage.constant.ResponseEnum;
import com.fm.financemanage.constant.annotation.Require;
import com.fm.financemanage.exception.ParameterException;
import com.fm.financemanage.model.po.CompanyClassify;
import com.fm.financemanage.model.po.SysUser;
import com.fm.financemanage.model.vo.PageVo;
import com.fm.financemanage.model.vo.simcard.SimCardListVo;
import com.fm.financemanage.model.vo.simcard.SimCardNoticeListVo;
import com.fm.financemanage.model.vo.simcard.SimCardOpeartorVo;
import com.fm.financemanage.response.Callback;
import com.fm.financemanage.response.JsonData;
import com.fm.financemanage.service.ClassifyService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RequestMapping("/classify")
@Api(tags = "分类管理")
@RestController
@Validated
public class ClassifyController {

    @Autowired
    private ClassifyService classifyService;

    @Autowired
    private TokenComponent tokenComponent;


    @GetMapping("/")
    @ApiOperation("公司分类")
    public JsonData<PageVo<List<CompanyClassify>>> getList(HttpServletRequest request, HttpServletResponse response,
                                                         @RequestParam(name = "page", required = false) Integer page,
                                                           @ApiParam(name = "limit", value = "条数", required = true)
                                                         @RequestParam(name = "limit", required = false) Integer limit
    ) {


        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo(), classifyService.getList( page, limit));
    }


    @PostMapping("/")
    @ApiOperation("")
    public JsonData operator(HttpServletRequest request, HttpServletResponse response,
                             @RequestBody CompanyClassify companyClassify
    ) {
        classifyService.operator(companyClassify);
        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());
    }

    @Require
    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public JsonData operator(HttpServletRequest request, HttpServletResponse response,
                             @PathVariable("id") Integer id
    ) {
        classifyService.removeById(id);
        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());
    }




}
